This script creates a quick visualization of user-labeled shoreline contamination (SC) and creates a new shapefile that has been edited to remove areas where SC has been detected so that we can add some uncertainty measures later in the model.
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
##
## The legacy packages maptools, rgdal, and rgeos, underpinning this package
## will retire shortly. Please refer to R-spatial evolution reports on
## https://r-spatial.org/r/2023/05/15/evolution4.html for details.
## This package is now running under evolution status 0
## [[1]]
## [1] "lubridate" "forcats" "stringr" "dplyr" "purrr" "readr"
## [7] "tidyr" "tibble" "ggplot2" "tidyverse" "stats" "graphics"
## [13] "grDevices" "utils" "datasets" "methods" "base"
##
## [[2]]
## [1] "sf" "lubridate" "forcats" "stringr" "dplyr" "purrr"
## [7] "readr" "tidyr" "tibble" "ggplot2" "tidyverse" "stats"
## [13] "graphics" "grDevices" "utils" "datasets" "methods" "base"
##
## [[3]]
## [1] "mapview" "sf" "lubridate" "forcats" "stringr" "dplyr"
## [7] "purrr" "readr" "tidyr" "tibble" "ggplot2" "tidyverse"
## [13] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
## [19] "base"
labels_file <- list.files('data/labels/', full.names = T)
labels <- read_csv(labels_file)
## Rows: 7862 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): mission, class, vol_init
## dbl (11): lat, lon, Red, Green, Blue, B5, B6, B7, B8, B11, B12
## date (1): date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
aoi <- st_read('data/aoi/Superior_AOI_modeling.shp')
## Reading layer `Superior_AOI_modeling' from data source
## `/Users/steeleb/Documents/GitHub/Superior-Plume-Bloom/data/aoi/Superior_AOI_modeling.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 1 feature and 1 field
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -92.09412 ymin: 46.56115 xmax: -90.1 ymax: 47.30476
## Geodetic CRS: NAD83
sc_labels <- labels %>%
filter(class == 'shorelineContamination')
The crs is WGS 84, so let’s save these as a sf
sc <- st_as_sf(sc_labels, coords = c('lon', 'lat'), crs = 'EPSG:4326')
#and then convert to the crs of the aoi
aoi_crs <- st_crs(aoi)
sc <- st_transform(sc, aoi_crs)
And plot to see where they are in conjunction with the shapefile
ggplot() +
geom_sf(data = aoi) +
geom_sf(data = sc, color = 'red') +
theme_minimal()
As expected, this has pretty good coverage, especially since there are 875 labels.
Let’s buffer these points by 60m and snip the polygon to account for these areas of contamination.
sc_buff <- st_buffer(sc, dist = 60)
# then perform a union so that there's only one feature
sc_buff_1 <- st_union(sc_buff)
# check to make sure
mapview(aoi) +
mapview(sc_buff_1)
And now remove those areas from the polygon
# make geometries valid
aoi <- st_make_valid(aoi)
sc_buff_1 <- st_make_valid(sc_buff_1)
# remove areas of sc_buff from original aoi
aoi_no_sc <- st_difference(aoi, sc_buff_1)
## Warning: attribute variables are assumed to be spatially constant throughout
## all geometries
mapview(aoi_no_sc)